package cn.lidongyu.org.controller;

import cn.lidongyu.basic.AjaxResult;
import cn.lidongyu.basic.PageList;
import cn.lidongyu.org.domain.Employee;
import cn.lidongyu.org.query.EmployeeQuery;
import cn.lidongyu.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emp")
public class EmployeeController {
    @Autowired
    private IEmployeeService employeeService;
    @GetMapping("/{id}")
    public Employee QueryOne(@PathVariable("id") Long id){
        return employeeService.findOne(id);
    }
    @GetMapping
    public List<Employee>QueryAll(){
        return employeeService.findAll();
    }
    @PutMapping
    public AjaxResult save(@RequestBody Employee department) {

        if (department.getId() == null) {
            employeeService.add(department);
        } else {
            employeeService.update(department);
        }
        return AjaxResult.me();
    }
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){

            employeeService.delete(id);
            return AjaxResult.me();

    }
    @PostMapping
    public PageList<Employee> findByQuery(@RequestBody EmployeeQuery departmentQuery){
        return employeeService.findByQuery(departmentQuery);
    }
    @PatchMapping
    public AjaxResult deletemore(@RequestBody List<Long> ids){

            employeeService.deletemore(ids);
            return AjaxResult.me();
        
    }
}
